package cn.larry.common.google;

/**
 * This is created,
 * but not necessarily updated by me.
 * Therefore, AUTHOR is useless.
 * 2024/8/28 08:28
 * 【test】
 *
 * @Version 1.0
 */
public class GoogleAuthTest {

    public static void main(String[] args) {

        /**
         * 1、生成用户密钥（密钥需要存入库中，验证code需要使用）
         */
        String userSecret = GoogleAuthenticatorTool.generateSecretKey(10);
        System.out.println(userSecret);

        /**
         * 2、把这个qrCode生成二维码，用google身份验证器扫描二维码就能添加成功
         */
        String qrCode = GoogleAuthenticatorTool.getQRBarcode("llin_test@test.com", userSecret);
        System.out.println(qrCode);

        /**
         * 3、验证code
         */
        long code = 760890;// 验证码
        long t = System.currentTimeMillis();
        GoogleAuthenticatorTool ga = new GoogleAuthenticatorTool();
        ga.setWindowSize(2);// default 2 ~ max 15
        boolean r = ga.checkCode("userSecret", code, t);
        System.out.println("检查code是否正确？\n" + r);
    }

}
